<script lang="ts" setup>
const props = defineProps<{
  list?: any
}>()

/** 传入值返回优惠券规则 */
const convertText = (item: any) => {
  if (item.threshold) {
    return `满${item.threshold}元可用`
  } else if (!item.threshold && item.discountsType === 2) {
    return `无门槛`
  } else {
    return `无门槛立减`
  }
}

const emits = defineEmits<{
  (event: 'triggerRules', couponItem: any): void
}>()
</script>

<template>
  <view class="couponItem_box" v-for="couponItem in props.list" :key="couponItem.id">
    <view class="_left">
      <view class="couponType">{{
        couponItem?.type === 1
          ? '满减券'
          : couponItem?.type === 2
          ? '折扣券'
          : couponItem?.type === 3
          ? '单品券'
          : couponItem?.type === 4
          ? '新人券'
          : couponItem?.type === 5
          ? '霸王免单券'
          : ''
      }}</view>
      <view v-if="couponItem?.type === 5" class="freeOfCharge">免单</view>
      <view v-else class="couponPriceBox">
        <view class="couponPrice_box">
          <view class="couponPrice">{{ couponItem?.discounts }}</view>
          {{ couponItem.discountsType === 1 ? '元' : '折' }}
        </view>
        <view class="couponRule">{{ convertText(couponItem) }}</view>
      </view>
      <view class="top-semicircular"></view>
      <view class="bottom-semicircular"></view>
    </view>
    <view class="_right">
      <view class="couponName_box">
        <!-- couponItem.couponName -->
        <view class="couponName">{{ couponItem.couponName }}</view>
        <view @tap="emits('triggerRules', couponItem)" class="ruleButton"
          >使用规则
          <view class="iconfont icon_questionMark"></view>
        </view>
      </view>
      <view class="_remaining">{{ couponItem?.couponCount }}张</view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
.couponItem_box {
  width: 654rpx;
  height: 196rpx;
  border-radius: 16rpx;
  background: #fff;
  padding: 4rpx;
  margin-bottom: 20rpx;
  display: flex;
  align-items: center;
  overflow: hidden;
  ._left {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 208rpx;
    height: 190rpx;
    border-radius: 16rpx 0 0 16rpx;
    background: linear-gradient(90deg, rgba(138, 223, 75, 0.22) 0%, rgba(138, 223, 75, 0.08) 100%);
    z-index: 9;
    .couponType {
      position: absolute;
      left: 0;
      top: 0;
      min-width: 92rpx;
      height: 36rpx;
      line-height: 36rpx;
      text-align: center;
      font-size: 20rpx;
      color: #488b16;
      padding: 0 16rpx;
      border-radius: 16rpx 0px;
      background: linear-gradient(90deg, rgba(138, 223, 75, 0.6) 0%, rgba(138, 223, 75, 0) 100%);
    }
    .top-semicircular {
      position: absolute;
      top: -20rpx;
      right: -16rpx;
      width: 32rpx;
      height: 32rpx;
      border-radius: 50%;
      background: #dbf8c6;
    }
    .bottom-semicircular {
      position: absolute;
      bottom: -20rpx;
      right: -16rpx;
      width: 32rpx;
      height: 32rpx;
      border-radius: 50%;
      background: #dbf8c6;
    }
    .freeOfCharge {
      font-size: 48rpx;
      color: #488b16;
    }
    .couponPriceBox {
      display: flex;
      flex-direction: column;
      align-items: center;
      .couponPrice_box {
        display: flex;
        align-items: baseline;
        min-width: 56rpx;
        height: 68rpx;
        color: #488b16;
        font-size: 24rpx;
        .couponPrice {
          font-size: 56rpx;
        }
      }
      .couponRule {
        margin-top: 8rpx;
        min-width: 56rpx;
        height: 34rpx;
        font-size: 24rpx;
        color: #488b16;
      }
    }
  }
  ._right {
    flex: 1;
    display: flex;
    align-items: center;
    height: 196rpx;
    position: relative;
    z-index: 9;
    .couponName_box {
      width: 240rpx;
      white-space: normal;
      word-wrap: break-word;
      word-break: break-all;
      margin-left: 42rpx;
      .couponName {
        font-size: 30rpx;
        color: #000;
      }
      .ruleButton {
        margin-top: 8rpx;
        display: flex;
        align-items: center;
        font-size: 24rpx;
        color: #00000080;
        .icon_questionMark {
          margin-left: 12rpx;
          font-size: 24rpx;
        }
      }
    }
    ._remaining {
      position: absolute;
      right: -68rpx;
      top: 15rpx;
      font-size: 24rpx;
      color: #fff;
      width: 200rpx;
      height: 40rpx;
      text-align: center;
      background: #ff714c;
      transform: rotate(45deg);
    }
  }
}
.couponItem_box:last-child {
  margin-bottom: 0px;
}
</style>
